package com.itheima.reggie.config;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class SpringConcectUtil implements ApplicationContextAware {
    private static ApplicationContext applicationContext;

    public SpringConcectUtil() {
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        if (SpringConcectUtil.applicationContext == null){
            SpringConcectUtil.applicationContext = applicationContext;
        }
    }

    public static ApplicationContext getApplicationContext(){
        return applicationContext;
    }

    public static Object getBean(String name){
        return applicationContext.getBean(name);
    }

    public static Object getBean(Class<?> requirType){
        return applicationContext.getBean(requirType);
    }
}
